﻿using ECGadmin.Common;

namespace ECGadmin.DAL
{
    public partial class DiscountRequirementDb
    {
        /// <summary>
        /// Lấy về danh sách DiscountRequirement theo DiscountId
        /// </summary>
        /// <param name="discountId"></param>
        /// <returns></returns>
        public static DiscountRequirementDto GetByDiscountId(int discountId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_DiscountRequirement_GetByDiscount");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@DiscountId", discountId));
                return dao.GetSingleDTO<DiscountRequirementDto>(ref command);
            }
            finally
            {
                command.Connection.Close();
            }
        }

        /// <summary>
        /// Xóa bản ghi trong bảng DiscountRequirement và Setting dựa vào DiscountId
        /// </summary>
        /// <param name="discountId"></param>
        /// <returns></returns>
        public static int DeleteDiscountRequirement(int discountId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_DiscountRequirement_DeleteByDiscountId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@DiscountId", discountId));
                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }
    }
}
